#ifndef _COMM_H
#define _COMM_H

#include "r_cg_macrodriver.h"

#define USER_CMD_INDEX_NONE       0x00
#define USER_CMD_INDEX_SET        0x01
#define USER_CMD_INDEX_GET_F0     0x02
#define USER_CMD_INDEX_GET_F1     0x03
#define USER_CMD_INDEX_GET_F2     0x04
#define USER_CMD_INDEX_INF        0x05


/* transmit command */
#define TEXT_SET        0x53
#define TEXT_GET        0x47
#define TEXT_RES        0x52
#define TEXT_INF        0x49
#define TEXT_ACK        0x41
#define TEXT_NAK        0x4E


#define CMD_SOFTWEAR_VER        0x10  //softwear version
#define CMD_WIFI_PROTOCOL       0x11  //
#define CMD_REAL_TIME           0x12
#define CMD_MACHINE_DATA        0xF0
#define CMD_RUN_STATE           0xF1
#define CMD_SERVICE_DATA        0xF2
#define CMD_KEY_SETTING         0xF4


//#define SET_KEY_CHILDLOCK       0x00
#define SET_KEY_POWER           0x01//0x00
#define SET_KEY_NORMALMODE      0x02
#define SET_KEY_WATERSHOCK      0x03
#define SET_KEY_BATHMODE        0x04
#define SET_KEY_ECO             0x0A
#define SET_KEY_TEMPUP          0x19
#define SET_KEY_TEMPDOWN        0x1A
#define SET_KEY_TEMPSET         0x1B
#define SET_KEY_NONE            0XFF

#define COMM_TIMEOUT            59//250
#define COMM_TIMEOUT_INIT       77

#define STXdata 0
#define SORTdata 1
#define LENGTHdata 2
#define COMMANDdata 3
#define TEXTdata 4
#define ETXdata 5
#define BCCdata 6

#define stx_date 0x02
#define sort_date 0x09
#define etx_date 0x03



typedef union
{
    uint8_t  buf[70];
    struct
    {
		uint8_t head; 
		uint8_t lenth;
		uint8_t msg_type;
		uint8_t msg_id;
		uint8_t cmd_type;
		uint8_t cmd_id;
		uint8_t mcu_data[64];     
    }pkt;
}SEND_FRAME_u;

typedef union
{
    uint8_t  buf[70];
    struct
    {
		uint8_t head; 
		uint8_t lenth;
		uint8_t msg_type;
		uint8_t msg_id;
		uint8_t cmd_type;
		uint8_t cmd_id;
		uint8_t mcu_data[64];     
    }pkt;
}GET_FRAME_u;

extern GET_FRAME_u get_data;
extern SEND_FRAME_u send_data;

 void comm_process(void);
 uint8_t checksum(uint8_t *buf,uint8_t size);

 
#endif